package com.baimawangzi.recovery.service.impl;

import com.baimawangzi.recovery.bean.Activity;
import com.baimawangzi.recovery.bean.PageBean;
import com.baimawangzi.recovery.dao.ActivityDao;
import com.baimawangzi.recovery.dao.impl.ActivityDaoImpl;
import com.baimawangzi.recovery.service.ActivityService;

import java.util.List;

public class ActivityServiceImpl implements ActivityService {
    private ActivityDao activityDao=new ActivityDaoImpl();

    @Override
    public List<Activity> findByLimit(int m, int n) {
        return activityDao.findByLimit(m,n);
    }

    @Override
    public int add(Activity activity) {
        return activityDao.add(activity);
    }

    @Override
    public int delete(int id) {
        return activityDao.delete(id);
    }

    @Override
    public Activity findById(int id) {
        return activityDao.findById(id);
    }

    @Override
    public int update(Activity activity) {
        return activityDao.update(activity);
    }

    @Override
    public PageBean<Activity> getPageBean(int currentPage, int pageSize) {
        PageBean<Activity> pageBean = new PageBean<>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalSize(activityDao.getCount());
        if (pageBean.getTotalSize()%pageSize==0){
            pageBean.setTotalPage(pageBean.getTotalSize()/pageSize);
        }
        else {
            pageBean.setTotalPage(pageBean.getTotalSize()/pageSize+1);
        }
        int m =(currentPage-1)*pageSize;
        pageBean.setData(activityDao.findByLimit(m,pageSize));
        return pageBean;
    }
}
